/**
 * 
 */
package net.sf.cldsql.sql2json.demo;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;

import net.sf.cldsql.dj.container.DiContainer;
import net.sf.cldsql.dj.mvc.DiServiceImpl;
import net.sf.cldsql.dj.utl.JsonUtl;
import net.sf.cldsql.sql2json.main.SjService;
import net.sf.cldsql.sql2json.utl.SjContext;
import net.sf.cldsql.sql2json.utl.SjResult;

/**
 * SjDemoServiceImpl
 */
public class SjDemoServiceImpl extends DiServiceImpl implements SjDemoService {
    @SuppressWarnings("serial")
    public Object execGet (final Object... args) {
        
        SjDemoQuery query = container.get(SjDemoQuery.class);
        final List<Map<String, Object>> rset = query.execGet((SjContext)args[0], 
                new HashMap<String, String>() {{put("id", (String)args[1]);}});
        
        return new SjResult(rset);
    }

    public Object execGetAll(final Object... args) {
        
        SjDemoQuery query = container.get(SjDemoQuery.class);
        final List<Map<String, Object>> rset = query.execGetAll((SjContext)args[0], null);
        
        return new SjResult(rset);
    }

    public Object execPost(final Object... args) {
        
        SjDemoQuery query = container.get(SjDemoQuery.class);
        final List<Map<String, Object>> rset = query.execPost((SjContext)args[0], 
                new HashMap<String, String>() {{
                    put("id", (String)args[1]);
                    put("name", (String)args[1]);
                }});
        
        return new SjResult(rset);
    }

    public Object execPut(final Object... args) {
        
        SjDemoQuery query = container.get(SjDemoQuery.class);
        final List<Map<String, Object>> rset = query.execPut((SjContext)args[0], 
                new HashMap<String, String>() {{
                    put("name", (String)args[1]);
                }});
        
        return new SjResult(rset);
    }

    public Object execDelete(final Object... args) {
        
        SjDemoQuery query = container.get(SjDemoQuery.class);
        final List<Map<String, Object>> rset = query.execDelete((SjContext)args[0], 
                new HashMap<String, String>() {{
                    put("id", (String)args[1]);
                }});
        
        return new SjResult(rset);
    }
}
